#include<bits/stdc++.h>
//fangweibiaoqian
#define int long long
using namespace std;
const int N=1e5+5;
int t,n,a[N],c[N],cl[N];
signed main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>t;
	while(t--){
		int ans=-INT_MAX;
		cin>>n;
		for(int i=1;i<=n;i++){
			cin>>a[i];
		}
		for(int i=1;i<=n;i++){
			int x=i;
			memset(c,0,sizeof c);
			memset(cl,0,sizeof cl);
			cl[i]=1;
			for(int j=1;j<=i;j++){
				if(a[j]==a[x]){
					c[x]=a[j];
					x=j;
					cl[j]=1;
				}
			}
			x=i;
			for(int j=i+1;j<=n;j++){
				if(a[j]==a[x]){
					c[j]=a[x];
					x=j;
					cl[j]=1;
				}
			}
			for(int i=n;i>=1;i--){
				if(cl[i]==0){
					for(int j=i-1;j>=1;j--){
						if(cl[j]==0){
							if(a[i]!=a[j])break;
							else{
								c[i]=a[j];
								break;
							}
						}
					}
			    }
			}
			int sum=0;
			for(int i=1;i<=n;i++){
				sum+=c[i];
			}
			ans=max(ans,sum);
			
		}
		
		cout<<ans<<"\n";
		
	}
    return 0;
}
